package AAA;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;
import java.util.Map;

@WebServlet("/A")
public class A extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        resp.setContentType("text/html");
        PrintWriter writer = resp.getWriter();
        String name = req.getParameter("username");

        Enumeration<String> parameterNames = req.getParameterNames();
        while (parameterNames.hasMoreElements()){
            String parameterName = parameterNames.nextElement();
            writer.print(parameterName+"<br>");
        }

        Map<String, String[]> parameterMap = req.getParameterMap();
        for (Map.Entry<String, String[]> entry : parameterMap.entrySet()){
            String key = entry.getKey();
            String[] value = entry.getValue();
            writer.print(key+"<br>");
            for (String s : value){
                writer.print(s+"<br>");
            }
        }

        String password = req.getParameter("password");

        writer.print(name+"<br>");
        writer.print(password+"<br>");

        String[] hobbies = req.getParameterValues("hobby");
        for (String hobby : hobbies){
            writer.print(hobby+"<br>");
        }

    }
}
